﻿using System.Collections.Generic;
using System.Windows.Navigation;

namespace Store.WP7.ViewModels
{
    public class PageViewModelBase : ViewModelBase
    {
        #region Navigation
        protected NavigationService NavigationService;
        protected NavigationContext NavigationContext;

        public virtual void OnNavigatedTo(NavigationService navigationService, NavigationContext navigationContext, IDictionary<string, object> state, NavigationEventArgs e)
        {
            NavigationService = navigationService;
            NavigationContext = navigationContext;
        }

        public virtual void OnLoaded() { }

        public virtual void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) { }

        public virtual void OnNavigatingFrom(NavigatingCancelEventArgs e, IDictionary<string, object> state) { } 
        #endregion

        #region Progress Indicator View Model
        private string _busyMessage;
        public string BusyMessage
        {
            get { return _busyMessage; }
            set
            {
                _busyMessage = value;
                RaisePropertyChanged(() => BusyMessage);
            }
        }

        private bool _isBusy;
        public bool IsBusy
        {
            get { return _isBusy; }
            set
            {
                _isBusy = value;
                RaisePropertyChanged(() => IsBusy);
            }
        }

        protected void UpdateBusyIndicator(string message, bool isBusy)
        {
            BusyMessage = message;
            IsBusy = isBusy;
        }

        protected void ResetBusyIndicator()
        {
            BusyMessage = string.Empty;
            IsBusy = false;
        } 
        #endregion
    }
}
